import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

const store = new Vuex.Store({
    state: {
        loginState: false,
        uid: localStorage.getItem('uid') || '',
        token: localStorage.getItem('token') || '',
        email: localStorage.getItem('email') || '',
        language: localStorage.getItem('language') || '',
    },
    mutations: {
        setLogin(state, data) {
            state.loginState = data;
        },
        setUid(state, data) {
            state.uid = data;
            localStorage.setItem("uid", data);
        },
        setToken(state, data) {
            state.token = data;
            localStorage.setItem("token", data);
        },
        setEmail(state, data) {
            state.email = data;
            localStorage.setItem("email", data);
        },
        setLanguage(state, data) {
            state.language = data;
            localStorage.setItem("language", data);
        },
    },
    getters: {

        loginState: state => state.loginState, // 正确命名 getter
        uid: state => state.uid,
        token: state => state.token,
        email: state => state.email,
        language: (state) => state.language,
        Reverse: state => {
            return state.language === 'ar' || state.language === 'fa';
        }
    },
});

export default store;
